This file describes the main files used to prepare the data and implement the structural estimation presented in the paper. It also describes the files used to conduct the counterfactual exercises presented and described in the paper.

The paper was estimated combining both Stata (versions 14 and 18) and Matlab (2024a and 2025a releases)

*****************
Data Preparation:
*****************

-> Data Cleanup: these files clean and prepare the datafiles from which the estimation sub-samples and csv files are created for estimation

- Code files:
	* SOC02_Analysis.do [merges tbl_hogares_soc_2002 and tbl_personas_soc_2002 and cleans all the relevant variables to be used for the reduced-form analysis and structural estimation]
	* SOC03_Analysis.do [merges tbl_hogares_soc_2003 and tbl_personas_soc_2003 and cleans all the relevant variables to be used for the reduced-form analysis and structural estimation]
	* SOC04_Analysis.do [merges tbl_hogares_soc_2004 and tbl_personas_soc_2004 and cleans all the relevant variables to be used for the reduced-form analysis and structural estimation]

- Input files:
	* tbl_hogares_soc_2002.dta [contains household-level characteristics collected in the 2002 survey]
	* tbl_hogares_soc_2003.dta [contains household-level characteristics collected in the 2003 survey]
	* tbl_hogares_soc_2004.dta [contains household-level characteristics collected in the 2004 survey]
	* tbl_personas_soc_2002.dta [contains individual-level information on employment, time use, and sociodemographic characteristics of each household member collected in the 2002 survey]
	* tbl_personas_soc_2003.dta [contains individual-level information on employment, time use, and sociodemographic characteristics of each household member collected in the 2003 survey]
	* tbl_personas_soc_2004.dta [contains individual-level information on employment, time use, and sociodemographic characteristics of each household member collected in the 2004 survey]

- Relevant output files:
	* tbl_merged_soc_2002_couples_v2.dta [to construct the two-parent households' datafiles for estimation]
	* tbl_merged_soc_YYYY_couples.dta [to construct the two-parent households' datafiles for estimation, where YYYY=2003,2004]
	* tbl_merged_soc_2002_Matched_v2.dta [to construct the singles' datafiles for estimation]
	* tbl_merged_soc_2003.dta [to construct the singles' datafiles for estimation]
	* tbl_merged_soc_2004.dta [to construct the singles' datafiles for estimation]

----------------
-> Preparation of intermediate datafiles with variables computed at the state, city block level and other variables that require intermediate computation

% Child-Related Variables Requiring Intermediate Computation
- Code files:
	* LocalWages.do	
	* NewChildRelatedVariables_ModelEst.do

- Input files:
	* bd_transf_urb_09jun10_uniqueIDhogar_strfolio.dta [this dataset contains the program's administration's universe of disbursements made bimonthly to beneficiary households]
	* tbl_merged_soc_YYYY_couples_v2.dta [where YYYY=2002,2003,2004]
	* tbl_merged_soc_2002_Matched_v2.dta [to construct the singles' datafiles for estimation]
	* tbl_merged_soc_2003_v2.dta [to construct the singles' datafiles for estimation]
	* tbl_merged_soc_2004_v2.dta [to construct the singles' datafiles for estimation]
	
- Relevant output files:
	* city_block_wages_YYYY.dta [where YYYY=2002,2003,2004] -- generated in LocalWages.do
	* locality_wages_YYYY.dta [where YYYY=2002,2003,2004] -- generated in LocalWages.do
	* components_Oportunidades_transfer_02-04.dta -- generated in NewChildRelatedVariables_ModelEst.do
	* child_related_monetary_vars_all_YYYY.dta -- generated NewChildRelatedVariables_ModelEst.do

% Computation of Sex Ratios at the State Level and Varying by Groups
- Code files:
	* additonal_distribution_factors.do

- Input files:
	* ipumsi_0006.dta

- Relevant output files:
	* sexratios_Mexico00-15_state.dta
	* sexratios_age_Mexico2000_state.dta
	
----------------
-> Preparation of estimation samples:
- Code files:
	* singles_YYYY_model_sample_transfer_breakdown.do [where YYYY=2002,2003,2004]
	* couples_YYYY_model_sample_transfer_breakdown.do [where YYYY=2002,2003,2004]
	* FileMerging02-04_ModelEst.do

- Input files:
	* tbl_merged_soc_YYYY_couples_v2.dta [where YYYY=2002,2003,2004]
	* tbl_merged_soc_YYYY_Matched_v2.dta [where YYYY=2002,2003,2004]
	* tbl_ahorro_actual_YYYY.dta [where YYYY=2002,2003,2004]
	* tbl_ahorro_actual_02_new.dta [data collected on savings in the 2002 survey]
	* tbl_ahorro_actual_2003_new.dta [data collected on savings in the 2003 survey]
	* tbl_ahorro_actual_2004_new.dta [data collected on savings in the 2004 survey]
	* sexratios_Mexico00-15.dta
	* sexratios_age_Mexico2000_state.dta
	* Pobreza2000.dta [Poverty rates by state, 2000; Obtained from the CONEVAL databases]
	* 

- Relevant output files:
	* YYYY_couples_model_estimation_transfer_savings.dta [where YYYY=2002,2003,2004] -- generated in couples_YYYY_model_sample_transfer_breakdown.do
	* YYYY_single_parents_estimation_sample_hprod.dta [where YYYY=2002,2003,2004] -- generated in singles_YYYY_model_sample_transfer_breakdown.do
	* YYYY_couple_estimation_sample_hprod.dta [where YYYY=2002,2003,2004]
	* 2002_couples_model_mdid.dta
	* couple_hprod_3wavescomplete_poor_pscores_apr2025.csv [contains the estimation sample for two-parent households] -- generated in FileMerging02-04_ModelEst.do
	* single_mothers_hprod_3wavescomplete_poor_apr2025.csv [contains the estimation sample for single-mother households] -- generated in FileMerging02-04_ModelEst.do
	* single_fathers_hprod_3wavescomplete_poor_apr2025.csv [contains the estimation sample for single-father households] -- generated in FileMerging02-04_ModelEst.do


*************************************************************************
Estimation of Quasi-Experimental Moments to Target in the GMM Estimation:
*************************************************************************
- Code files:
	* Stata: main_estimation_step1.do [prepares the propensity scores and files for the matching in Matlab]
	* Matlab:kernel_matching_quasiexp_moments.m [implements the matching algorithm based on the propensity scores]

- Input files:
	* 2002_couples_model_mdid.dta
	* 2002_couples_model_estimation_transfer_savings.dta
	* 2004_couples_model_estimation_transfer_savings.dta

- Relevant output files:
	* deltas_step1.csv

**************
GMM Estimation
**************
-> Step 2a: Estimation of home production parameters
- Code files:
	* estimation_hprod_step2A.m [main estimation file that carries out the two-step GMM of the production function of all household types]
	* Function files called in the main estimation file:
		# hprod_fcn_couples.m [objective function for the GMM estimated on couples-headed households]
		# hprod_fcn_singles.m [objective function for the GMM estimated on single-headed households]
		# hprod_fcn_couples_resid.m [computes the residuals from the first step of the GMM estimator to construct the weight matrix for the second step of the GMM estimator, couple-headed households]
		# hprod_fcn_singles_resid.m [computes the residuals from the first step of the GMM estimator to construct the weight matrix for the second step of the GMM estimator, single-headed households]

- Input files:
	* couple_hprod_3wavescomplete_poor_pscores_apr2025.csv [contains the estimation sample for two-parent households]
	* single_mothers_hprod_3wavescomplete_poor_apr2025.csv [contains the estimation sample for single-mother households]
	* single_fathers_hprod_3wavescomplete_poor_apr2025.csv [contains the estimation sample for single-father households]
	* initial_guesses_hprod_twoparent_022025.csv [initial guesses used for two-parent households]
	* complete_initial_guesses_091520.xlsx [initial guesses used for single-parent households]
		
- Relevant output files:
	* hprod_params_twoparentHHs_apr2025.csv [production function parameters for two-parent households]
	* hprod_params_singlemotherHHs_apr2025.csv [production function parameters for single-mother households]
	* hprod_params_singlefatherHHs_apr2025.csv [production function parameters for single-father households]

---------------- 
-> Step 2b: Estimation of preference and Pareto weight parameters
- Code files:
	* estimation_preferences_bargaining_step2b.m [main estimation file that carries out the two-step GMM]
	* Function files called in the main estimation file:
		# h_fcn_step2B_v2_qexp_newparam.m [contains the objective function to be optimized over in the second step of the GMM estimator]
		# Deriv_F1_1.m [takes the numerical derivative of the objective function in the second step of the GMM with respect to the parameters estimated in the first step of the GMM]
		# h_fcn_deriv_step2B_qexp.m [computes the residuals from the objective function of the second step of the GMM estimator]
		# DerivFQ.m [computes the residuals from the objective function of the second step of the GMM estimator]
		# DerivFQ_singles.m [takes the numerical derivative of the objective function used in the first step of the GMM for single-parent households]
		# hprod_fcn_deriv_couples.m [computes the residuals from the objective function of the first step of the GMM estimator for two-parent households]
		# hprod_fcn_deriv_single.m [computes the residuals of the objective function used in the first step of the GMM for single-parent households]
		# LatexParamsTable_ModelFit.m [creates the tex files with the model fit tables]

- Input files:
	* deltas_step1.csv [file containing the quasi-experimental moments to be targeted in this step of the GMM estimator presented in the paper, generated in the files described above]
	* couple_hprod_3wavescomplete_poor_pscores_apr2025.csv [contains the estimation sample for two-parent households]
	* single_mothers_hprod_3wavescomplete_poor_apr2025.csv [contains the estimation sample for single-mother households]
	* single_fathers_hprod_3wavescomplete_poor_apr2025.csv [contains the estimation sample for single-father households]
	* OptimalParams_hprod_spec1_allhhs_upd421_optW.csv [contains initial guesses for the estimation of this step of the GMM estimator]

- Relevant output files:
	* params_step2B_may2025.csv (from the estimation with identity matrix as weight matrix)
	* params_step2B_optW_may2025.csv (from the estimation with the weight matrix constructed with residuals from the estimation with the identity matrix as weight matrix)
	* all_moments_2parent_model_fit_tables.tex
	* all_moments_single_parent_model_fit_tables.tex
	* all_moments_full_sample_model_fit.tex [this is the tex file that goes into the table presenting how well the model fits the moments in estimation]

----------------
-> Tables containing the parameter estimates 
- Code files:
	* postest_parameter_tables_with_SEs.m
	* Function files called in the main file that creates the parameter estimates tables:
		# STDERR_optW.m
		# DerivF1_1.m [takes the numerical derivative of the objective function in the second step of the GMM with respect to the parameters estimated in the first step of the GMM -- called in STDERR_optW.m]
		# DerivF1_2.m [takes the numerical derivative of the objective function in the second step of the GMM with respect to the parameters estimated in the second step of the GMM -- called in STDERR_optW.m]
		# h_fcn_deriv_step2B_v2_qexp.m [computes the residuals from the objective function of the second step of the GMM estimator -- called in STDERR_optW.m]
		# DerivFQ.m [takes the numerical derivative of the objective function used in the first step of the GMM for two-parent households -- called in STDERR_optW.m]
		# hprod_fcn_deriv_couples.m [computes the residuals from the objective function of the first step of the GMM estimator for two-parent households -- called in STDERR_optW.m] 
		# DerivFQ_single.m [takes the numerical derivative of the objective function used in the first step of the GMM for single-parent households -- called in STDERR_optW.m]
		# hprod_fcn_deriv_single.m [computes the residuals of the objective function used in the first step of the GMM for single-parent households -- called in STDERR_optW.m]
		# LatexParamsTable_v2.m

- Input files:
	* hprod_params_twoparentHHs_apr2025.csv
	* hprod_params_singlemotherHHs_apr2025.csv
	* hprod_params_singlefatherHHs_apr2025.csv
	* params_step2B_optW_may2025.csv
	* couple_hprod_3wavescomplete_poor_pscores_apr2025.csv [contains the estimation sample for two-parent households]
	* single_mothers_hprod_3wavescomplete_poor_apr2025.csv [contains the estimation sample for single-mother households]
	* single_fathers_hprod_3wavescomplete_poor_apr2025.csv [contains the estimation sample for single-father households]

- Relevant output files:
	* hprod_twoparentHHs_params_SEs_2025.tex
	* hprod_singlemotherHHs_params_SEs_2025.tex
	* hprod_singlefatherHHs_params_SEs_2025.tex
	* Pareto_weight_params_SEs_jun2025.tex
	* Wife_leisure_preference_params_SEs_jun2025.tex
	* Wife_priv_consumption_preference_params_SEs_jun2025.tex
	* Husband_leisure_preference_params_SEs_jun2025.tex
	* Husband_priv_consumption_preference_params_SEs_jun2025.tex

**************************************************
DID with Model-Simulated Data using GMM Estimates
**************************************************
Code files:
	* postest_DID_replication.do [simulates the time and consumption allocations using the parameter estimates obtained from the GMM routine]
	* Function files called in the main simulation file:
		# sim_intrahh_allocations.m [simulates the allocations in two-parent households]
		# sim_intrahh_allocations_singles [simulates the allocations in single-parent households]
	* did_replication.do [implements the DID estimator on the simulated data created in the Matlab simulation file]
	* postest_counterfactual_exercises.m [generates the predicted Pareto weight, domestic output and individual welfare measures for the "structural" DID used to capture the impact of the program on these measures
	* Function files called in the simulation on unobserved outcomes from the model:
		# sim_intrahh_measures.m [simulates the Pareto weight, domestic output, and individual welfare measures using the parameter estimates obtained in the GMM estimation]
	* treatment_effects_intrahh_outcomes.do [implements the DID estimator on the Pareto weight, domestic output, and individual welfare measures]

Input files:
	* hprod_params_twoparentHHs_apr2025.csv
	* hprod_params_singlemotherHHs_apr2025.csv
	* hprod_params_singlefatherHHs_apr2025.csv
	* params_step2B_optW_may2025.csv
	* couple_hprod_3wavescomplete_poor_pscores_apr2025.csv [contains the estimation sample for two-parent households]
	* single_mothers_hprod_3wavescomplete_poor_apr2025.csv [contains the estimation sample for single-mother households]
	* single_fathers_hprod_3wavescomplete_poor_apr2025.csv [contains the estimation sample for single-father households]

Relevant output files:
	* simulated_outcomes_for_did_replication.csv -- generated in postest_DID_replication.m
	* simulated_outcomes_for_single_mothers_did_replication.csv -- generated in postest_DID_replication.m
	* all_outcomes_combined_apr2025.csv -- generated in postest_counterfactual_exercises.m
	* did_replication_2parent_2025.tex -- generated in did_replication.do
	* did_replication_single_mothers_2025.tex -- generated in did_replication.do
	* structural_mdid_percentages_apr2025.tex -- generated in treatment_effects_intrahh_outcomes.do
	
************************
Counterfactual exercises
************************

-> Counterfactual exercises that target wage subsidies and randomized cash transfers in the main estimation sample of two-parent households

Code files:
	* postest_counterfactual_exercises.m
	* Function files:
		# sim_intrahh_measures.m [simulates the Pareto weight, domestic output, and individual welfare measures using the parameter estimates obtained in the GMM estimation]

Input files:
	* hprod_params_twoparentHHs_apr2025.csv
	* hprod_params_singlemotherHHs_apr2025.csv
	* hprod_params_singlefatherHHs_apr2025.csv
	* params_step2B_optW_may2025.csv
	* couple_hprod_3wavescomplete_poor_pscores_apr2025.csv [contains the estimation sample for two-parent households]
	* single_mothers_hprod_3wavescomplete_poor_apr2025.csv [contains the estimation sample for single-mother households]
	* single_fathers_hprod_3wavescomplete_poor_apr2025.csv [contains the estimation sample for single-father households]		

Relevant output files:
	* lambda_wage_subsidy_counterfactual_25_bw.png
	* domestic_production_subsidy_counterfactual_25_bw.png
	* mmwiA_subsidy_counterfactual_25_bw.png
	* mmwiB_subsidy_counterfactual_25_bw.png
	* lambda_wage_subsidy_counterfactual_40_bw.png
	* domestic_production_subsidy_counterfactual_40_bw.png
	* mmwiA_subsidy_counterfactual_40_bw.png
	* mmwiB_subsidy_counterfactual_40_bw.png
	* lambda_alt_cash_transfers_bw.png
	* domestic_production_alt_cash_transfers_bw.png
	* mmwiA_alt_cash_transfers_bw.png
	* mmwiB_alt_cash_transfers_bw.png

----------------
-> Counterfactual exercises that targets cash transfers to non-poor households and simulates their impact on the simulated outcomes of interest

Code files:
	* individual_poverty_analyis_nonpoor.m (+)
	* Function files called in the main Matlab file implementing the individual level poverty analysis:
		# sim_intrahh_measures.m

Input files:
	* couple_hprod_3waves_complete_fullSample_pscores_apr2025.csv
	* hprod_params_twoparentHH_full_sample_2025.csv
	* hprod_params_singlemothers_full_sample_2025.csv
	* hprod_params_singlefathers_full_sample_2025.csv
	* params_step2B_optW_full_sample_2025.csv

Output files:
	* intrahousehold_poverty_nonpoorHHs.tex
	* lambda_counterfactual_ind_poor_bw.png
	* Qhat_counterfactual_ind_poor_bw.png
	* mmwiA_counterfactual_ind_poor_bw.png
	* mmwiB_counterfactual_ind_poor_bw.png

(+) Note: this file takes as inputs the sample including non-poor households that were not included in the main estimation of the model and the parameter estimates obtained from the GMM estimated on the full sample that includes both poor and non-poor housseholds. The files related to this intermediate estimation step are the following:
Data Preparation Code: FileMerging_02-04_ModelEst_InclNonPoorHHs.do
Data Output: couple_hprod_3wavescomplete_fullSample_pscores_apr2025.csv, single_mothers_hprod_3wavescomplete_fullSample_apr2025.csv, single_fathers_hprod_3wavescomplete_fullSample_apr2025.csv
Estimation Code: estimation_step2A_full_sample_2025.m, estimation_step2B_full_sample_2025.m (takes as initial guesses the file params_step2B_may2025.csv)
Estimation Output: hprod_params_twoparentHH_full_sample_2025.csv, hprod_params_singlemothers_full_sample_2025.csv, hprod_params_singlefathers_full_sample_2025.csv, params_step2B_optW_full_sample_2025.csv
